/**
 * Copyright (C) 2010  Johan Basson
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */
package symorg.util;

/**
 *
 * @author johan
 */
public class NodeList {

    private Node[] items;
    private int current;

    public NodeList() {
        current = 0;
        items = new Node[5];
    }

    public void add(Node o) {
        current++;
        if (current < items.length) {
            items[current] = o;
        } else {
            int newCapacity = items.length + (items.length / 4);
            Node[] newArr = new Node[newCapacity];
            System.arraycopy(items, 0, newArr, 0, items.length);
            items = newArr;
            items[current] = o;
        }
    }

    public int size() {
        return items.length;
    }

    public Node get(int pos) {
        if (pos <= items.length) {
            return items[pos];
        } else {
            return null;
        }
    }
}
